import functools
import wx

class ActionPanel(wx.Panel):
    def __init__(self, actions, frame, *args, **kwargs):
        wx.Panel.__init__(self, *args, **kwargs) 
        self._buttons = []
        self._frame = frame
        for i in range(0, 6):
            self._buttons.append(wx.Button(self, 
                                          wx.ID_ANY, 
                                          "",
                                          pos=(0 + i * 100, 0),
                                          size=(100,30)))
            self._buttons[i].Bind(wx.EVT_BUTTON, functools.partial(self.on_button, index=i))
            self._buttons[i].Bind(wx.EVT_MOTION, functools.partial(self.on_button_motion, 
                                                                   index=i))
        self.update(actions)
        
    def update(self, actions):
        count = 0
        for action in actions:
            self._buttons[count].SetLabel(action.name)
            self._buttons[count].Enable(action.enabled)
            count += 1
        for i in range(count, 6):
            self._buttons[i].SetLabel("None")
            self._buttons[i].Enable(False)

    def on_button(self, event, index):
        self._frame.execute_action(index)
    
    def on_button_motion(self, event, index):
        self._frame.display_action_tooltip(index)
